﻿#ifndef _CSEMAPHORE__H_
#define _CSEMAPHORE__H_

#include "kernel/event/event.h"

namespace FD
{
	namespace Kernel
	{
		struct FD_SEMAPHORE_DATA;
		/// <summary>
		/// 信号量类
		/// </summary>
		class FD_Kernel_Export Semaphore : public FD::Kernel::EventObject
		{
		public:
			/// <summary>
			/// 构造信号量
			/// </summary>
			/// <param name="MaxCount">资源的最大可用数</param>
			/// <param name="InitialCount">资源的初始可用数</param>
			/// <returns></returns>
			Semaphore(uint32 nMaxCount, uint32 nInitialCount);
			~Semaphore();
		public:
			/// <summary>
			/// 使用指定数量的信号，P操作
			/// </summary>
			/// <param name="count">使用的信号量数</param>
			/// <returns>成功返回true,否则false</returns>
			bool wait(uint32 count);
			/// <summary>
			/// 使用一个数量的信号，P操作
			/// </summary>
			/// <param name="></param>
			/// <returns>成功返回true,否则false</returns>
			bool waitOne();
			/// <summary>
			/// 恢复指定数量的信号，V操作
			/// </summary>
			/// <param name="count">恢复的信号量数</param>
			/// <returns>成功返回true,否则false</returns>
			bool release(uint32 count);
			/// <summary>
			/// 恢复一个数量的信号，V操作
			/// </summary>
			/// <param name="></param>
			/// <returns>成功返回true,否则false</returns>
			bool releaseOne();
		private:
			FD_SEMAPHORE_DATA *m_pData;
		};
	}
}

#endif

